Add zipWith to NonEmptyList and NonEmptyVector - #1885
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1885 +/- ##
==========================================
+ Coverage 94.97% 94.97% +<.01%
==========================================
Files 241 241
Lines 4199 4202 +3
Branches 106 112 +6
==========================================
+ Hits 3988 3991 +3
Misses 211 211
Continue to review full report at Codecov.
|
| * }}} | ||
| */ | ||
| def zipWith[B, C](b: NonEmptyVector[B])(f: (A, B) => C): NonEmptyVector[C] = | ||
| NonEmptyVector.fromVectorUnsafe((toVector, b.toVector).zipped.map(f)) |
There was a problem hiding this comment.
I think this will be maybe faster if we do:
toVector.iterator.zip(b.toVector.iterator).map(f).toVectorI think the current code has to allocate a NonEmptyVector after zipped and then another one after map.
But I'm just guessing since I don't know this tuple enrichment. Can you comment as to why this is incorrect if I am wrong?
There was a problem hiding this comment.
Yes of course! I'm on my phone right now, but if you look at the source for zipped https://github.com/scala/scala/tree/v2.12.3/src/library/scala/runtime/Tuple2Zipped.scala#L1 you'll see that it does not actually iterate over either of the vectors until you call map or any of the other methods :)
|
👍 |
Should resolve #1870